#ifndef __UPGRADE_H__
#define __UPGRADE_H__

#include "upgrade_thm36.h"
#include "upgrade_ccm4201s.h"
#include "upgrade_acm32.h"

#define CONF_FILE_PATH "/usr/share/deepin-authentication/modes/ofprint2686-serverd/"
#define FW_VERSION_FILE "/usr/share/deepin-authentication/modes/ofprint2686-serverd/upgrade_fw.conf"


//#define CCM4201S_FW_VERSION_HEAD  "ccm4201s_bzy_2553_"
#define CCM4201S_FW_VERSION_HEAD    "ccm4201s_bzy_2565_"
//#define CCM4201S_FW_VERSION_HEAD  "AFP058_FW_"

#define THM36_FW_VERSION_HEAD       "thm36_bzy_FWversion"
#define ACM32_FW_VERSION_HEAD       "acm32_btl_ofilm_pc_"
#define FW_FILE_TAIL                ".bin"

#define FILE_PATH_LEN_MAX       1024
#define FW_CONF_FILE_SIZE_MAX   256
#define FW_FILE_NAME_LEN_MAX    50
#define FW_VERSION_LEN_MAX      50
#define FW_VERSION_NUM_LEN_MAX  6

#define FW_FILE_SIZE_MIN    (10*1024)
#define FW_FILE_SIZE_MAX    (2*1024*1024)

#define UPGRADE_FILE(x) upgrade_new_firmware_name((x))
#define FIRMWARE_VERSION_NEW(x) upgrade_new_firmware_version((x))
#define FIRMWARE_VERSION_NUM_NEW    upgrade_new_firmware_version_num()

typedef enum _DEVICE_MCU_TYPE_ENUM_
{
    THM36 = 0x01,
    CCM4201 = 0x02,
    ACM32 = 0x03,
}DEVICE_MCU_TYPE_ENUM;

typedef enum _DEVICE_USB_MCU_TYPE_ENUM_
{
    DEVICE_THM36 = (0x01 << 0),
    DEVICE_CCM4201S = (0x01 << 1),
    DEVICE_ACM32 = (0x01 << 2),
}DEVICE_USB_MCU_TYPE_ENUM;


typedef struct _FIRMWARE_VERSION_INFO_
{
    char file_path[FILE_PATH_LEN_MAX+FW_FILE_NAME_LEN_MAX];
    char fw_version[FW_VERSION_LEN_MAX];
    uint32 fw_version_num;
}FIRMWARE_VERSION_INFO;


typedef struct _UPGRADE_PARAM_
{
    uint8 fw_file_mcu_type;     //固件文件名称对应的mcu类别
    uint8 fw_version_mcu_type;  //固件版本号对应的mcu类别
    uint8 fw_boot_mcu_type;     //固件bootloader对应的mcu类别
    uint8 upgrade_state;//升级状态，0: 未升级；1: 正在升级

    FIRMWARE_VERSION_INFO acm32_fw;
    FIRMWARE_VERSION_INFO thm36_fw;
    FIRMWARE_VERSION_INFO ccm4201s_fw;

    ACM32_UPGRADE_PARAM acm32;
    THM36_UPGRADE_PARAM thm36;
    CCM4201S_UPGRADE_PARAM ccm4201s;
}UPGRADE_PARAM;


extern char new_firmware_name[FILE_PATH_LEN_MAX+FW_FILE_NAME_LEN_MAX];
extern char new_firmware_version[256];
extern uint32 new_firmware_version_num;

extern int32 upgrade_module_init(void);
extern int upgrade_and_run(void);
extern int read_fw_version(void);
extern char *upgrade_new_firmware_version(uint8 mcu_type);
extern char *upgrade_new_firmware_name(uint8 mcu_type);
extern uint32 upgrade_new_firmware_version_num(void);
extern uint8 upgrade_get_fw_file_mcu_type(void);
extern int32 upgrade_check_boot_mcu_type(void);
extern int check_fw_file_version(char *file_name);
extern FIRMWARE_VERSION_INFO *thm36_fw_upgrade_info(void);
extern FIRMWARE_VERSION_INFO *ccm4201_fw_upgrade_info(void);
extern FIRMWARE_VERSION_INFO *acm32_fw_upgrade_info(void);
extern int32 set_upgrade_state(uint8 state);
extern uint8 get_upgrade_state(void);




#endif //__UPGRADE_H__

